﻿using System.IO;
using System.Text;

namespace DataScripter.Scripting.Output
{
    public class FileScriptResult : IScriptResult
    {
        private readonly StreamWriter _writer;

        public FileScriptResult(string filename, bool append, Encoding encoding)
        {
            Filename = filename;
            Encoding = encoding;
            _writer = new StreamWriter(Filename, append, encoding);
        }

        public string Filename { get; private set; }
        private Encoding Encoding { get; set; }

        public void Close()
        {
            _writer.Flush();
            _writer.Close();
            _writer.Dispose();
        }

        public StreamWriter Writer
        {
            get { return _writer; }
        }

        public string Output
        {
            get { return File.ReadAllText(Filename, Encoding); }
        }
    }
}